using System;
using System.Collections.Generic;
using System.Text;

namespace Demo_G.O.S.E.ServerEngine.AIEngine.Agent
{
    /// <summary>
    /// This class is used to represent the parameters to construct a particular type of agent.
    /// </summary>
    public class AgentParams
    {
        /// <summary>
        /// The type of agent.
        /// </summary>
        private String type = null;

        /** The list of property names. */
        //private Vector properties = new Vector();

        /** A mapping of parameter names to their values as text. */
        //private HashMap valueMap = new HashMap();

        /// <summary>
        /// Constructs a new AgentParams object.
        /// </summary>
        /// <param name="type">The fully-qualified class name for the agent type.</param>
        public AgentParams( String type )
        {
            //if ( ( type == null ) || ( type.length() == 0 ) )
            //    throw new NullPointerException( "Type cannot be null or empty!" );
            //this.type = type;
        }

        /// <summary>
        /// Returns the fully-qualified class name for the agent type.
        /// </summary>
        public String Type
        {
            get { return type; }
        }

        /**
         * Returns the list of property names to be set for the agent.
         */
        //public Vector getProperties()
        //{
        //synchronized(properties) {
        //    return (Vector)properties.clone();
        //}
        //}

        /// <summary>
        /// Returns the value of a particular property as text.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public String GetValue( String name )
        {
            //synchronized(properties)
            //{
            //    return (String)valueMap.get(name);
            //}

            return null;
        }

        /// <summary>
        /// Adds a property to the list of properties.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        public void SetValue( String name, String value )
        {
            //synchronized(properties) {
            //    if(!properties.contains(name))
            //    properties.addElement(name);
            //    valueMap.put(name, value);
            //}
        }

        /// <summary>
        /// Constructs a new Agent from the type and properties that the AgentParams object contains.
        /// </summary>
        /// <returns></returns>
        public Agent Instance()
        {
            Agent agent = null;
            //Vector properties = getProperties();
            //try {
            //    Class clazz = Class.forName(type);
            //    agent = (Agent)clazz.newInstance();
            //    BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
            //    PropertyDescriptor[] descs = beanInfo.getPropertyDescriptors();
            //    for(int i = 0; i < descs.length; i++) {
            //    PropertyDescriptor desc = descs[i];
            //    String name = desc.getName();
            //    if(properties.contains(name)) {
            //        String asText = getValue(name);
            //        Class pClazz = desc.getPropertyType();
            //        PropertyEditor editor =
            //        PropertyEditorManager.findEditor(pClazz);
            //        editor.setAsText(asText);
            //        Object value = editor.getValue();
            //        Method setter = desc.getWriteMethod();
            //        Object args[] = {value};
            //        setter.invoke(agent, args);
            //    }
            //    }
            //} catch(Exception e) {
            //    e.printStackTrace();
            //}
            return agent;
        }

        /// <summary>
        /// Returns a String representation of this instance.
        /// </summary>
        /// <returns></returns>
        public override String ToString()
        {
            //return "<" + type + ">" + valueMap;
            return null;
        }
    }
}
